require("utils")
local utils = utils
local pairs = pairs
local rawget = rawget
local assert = assert
local setmetatable = setmetatable

module("gems")

blue = {
	sp_emp_saph = {
		stat = {
			spirit = 10,
		},
	},
	stam12 = {
		stat = {
			stamina = 12,
		},
	},
	stam6 = {
		stat = {
			stamina = 6,
		},
	},
	spi10 = {
		stat = {
			spirit = 10,
		},
	}
}

purple = {
	pure_pearl = {
		stat = {
			spirit = 4,
			healing = 9,
			spelldamage = 3,
		},
	},
	blessed_tanzanite = {
		stat = {
			healing = 11,
			stamina = 6,
		},
	},
	soothing_amethist = {
		stat = {
			healing = 11,
			stamina = 6,
		},
	},
	royal_nightseye = {
		stat = {
			healing = 9,
			spelldamage = 3,
			manareg = 2,
		},
	},
	royal_tanzanite = {
		stat = {
			healing = 11,
			manareg = 2,
		},
	},
	str_stam = {
		stat = {
			strength = 5,
			stamina = 6,
		},
	},
	agi_stam = {
		stat = {
			agility = 4,
			stamina = 6,
		},
	},
	ap8stam6 = {
		stat = {
			attackpower = 8,
			stamina = 6,
		}
	},
	str4stam6 = {
		stat = {
			strength = 4,
			stamina = 6,
		}
	},
	heal11spi5 = {
		stat = {
			spirit = 5,
			healing = 11,
			spelldamage = 4,
		},
	},
}

orange = {
	lum_noble_topaz = {
		stat = {
			intellect = 4,
			healing = 9,
			spelldamage = 3,
		}
	},
	dodge_hit = {
		stat = {
			cr_dodge = 5,
			cr_hit = 4,
		}
	},
	hit4agi4 = {
		stat = {
			cr_hit = 4,
			agi = 4,
		},
	},
	heal11int5 = {
		stat = {
			intellect = 5,
			healing = 11,
			spelldamage = 4,
		}
	},
}

meta = {
	healing = {
		stat = {
			healing = 26,
			spelldamage = 9,
		},
	},
	def = {
		stat = {
			stamina = 18,
		},
	},
	ap_run = {
		stat = {
			attackpower = 24,
		},
	},
	intemana = {
		stat = {
			intellect = 12,
		}
	}
}

green =  {
	def_stam = {
		stat = {
			cr_skill_defense = 4,
			stamina = 6,
		},
	},
}

red = {
	agility = {
		stat = {
			agility = 8,
		},
	},
	str4 = {
		stat = {
			strength = 4,
		},
	},
	str8 = {
		stat = {
			strength = 8,
		},
	},
	heal22 = {
		stat = {
			healing = 22,
			spelldamage = 8,
		},
	},
}

yellow = {
	hit8 = {
		stat = {
			cr_hit = 8,
		},
	},
	def4 = {
		stat = {
			cr_skill_defense = 4,
		},
	},
}

colors = {
	red = "primary",
	blue = "primary",
	yellow = "primary",
	purple = "secondary",
	orange = "secondary",
	green = "secondary",
	prismatic = "secondary",
	meta = "meta",
}

function valid(color, socket)
	if socket == "meta" then
		assert(color == "meta")
		return true
	else
		assert(color ~= "meta")
	end
	if color == "prismatic" then return true end
	if socket == "blue" then
		return color == "blue" or color == "purple" or color == "green"
	elseif socket == "red" then
		return color == "red" or color == "purple" or color == "orange"
	elseif socket == "yellow" then
		return color == "yellow" or color == "green" or color == "orange"
	end
	assert(false)
end

for color in pairs(colors) do
	local table = _M[color]
	if table then
		for name, entry in pairs(table) do
			entry.color = color
			assert(entry.stat or entry.color == "meta")
		end
		setmetatable(table, utils.check_mt)
	end
end
